# -*- coding: utf-8 -*-

import websocket
from dealmain.BaseDeal import *
from program.Account import Account
from program.Reminder import Reminder
R=Reminder()
A=Account()
programDict={'课程提醒':R,'记账助手':A}
def on_message(ws,msg):
    data=BaseMsg(msg)
    subType=data.subtype
    msgType=data.type
    if subType=='private':
        if msgType=='message':
            friendDealMessage(msg,programDict)
        else:
            friendDealEvent(msg,programDict)
    elif subType=='group':
        if msgType=='message':
            groupDealMessage(msg,programDict)
        else:
            groupDealEvent(msg,programDict)

def on_error(ws, error):
    print("连接失败:" + str(error))

def on_close(ws):
    print("连接已断开")

def on_open(ws):
    print("已连接到消息服务器")

def start():
    ws = websocket.WebSocketApp("ws://129.211.74.183:53392", on_message=on_message, on_error=on_error, on_close=on_close)
    ws.on_open = on_open
    ws.run_forever()


if __name__=="__main__":
    start()
